package org.hashdb.client.net.nio;

import io.netty.channel.ChannelHandlerContext;
import org.jetbrains.annotations.Nullable;

/**
 * Date: 2024/1/17 12:10
 *
 * @author huanyuMake-pecdle
 * @version 0.0.1
 */
public enum Protocol implements MetaEnum {
    HASH_V1(new V1HashProtocolCodec()),
    ;

    static final Protocol[] constant = values();

    private final ProtocolCodec codec;

    Protocol(ProtocolCodec codec) {
        this.codec = codec;
    }

    public static @Nullable Protocol resolve(ChannelHandlerContext ctx, byte b) {
        try {
            return constant[b];
        } catch (ArrayIndexOutOfBoundsException e) {
            return null;
        }
    }

    public ProtocolCodec codec() {
        return codec;
    }

    @Override
    public int key() {
        return ordinal();
    }
}
